#pragma once

#include "Duplicate/Duplicate.h"


//云端试炼（工会副本）
class CloudDuplicate : public Duplicate
{

public:
	explicit CloudDuplicate();
	virtual ~CloudDuplicate();
	////////////////////////////////  Duplicate  //////////////////////////////////////////
	//初始化
	virtual bool Init(uint32_t nDuplicateID, uint32_t nSceneID, IBrushMonster *pBrush);
	//
	virtual void UnInit();
	//活动状态
	virtual void ActivityState(uint32_t actId, int32_t state, SUnionActParam &param);
	//工会精英平均等级
	virtual int32_t UnionAverageLev();
	//积分怪物死亡
	virtual void ScoreMonsDie(uint32_t monsId, int32_t count, int8_t byBoss, uint64_t killerCid);
protected:
	virtual void OnReady_State();
	virtual void OnBegin_State();
	virtual void OnFinish_State();
	virtual void OnFlop_State();
	virtual void OnClean_State();
	virtual void OnDestory_State();
	//定时器更新
	virtual void OnTimerUpdate(uint32_t nTimerID);
	//执行事件
	virtual void OnExecuteEvent(uint16_t nEventID, uint32_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	//生物进入场景
	virtual void OnCreatureEnter(Creature *pCreature);
	//是否能进入
	virtual bool OnCanEnter(Creature *pCreature);
	//进入区域
	virtual bool OnEnterArea(uint32_t nAreaID);
	//复活
	virtual void OnRelive(Player *pPlayer, int8_t byType);
	//主动离开副本之前 的处理 
	virtual void OnActiveBeforeLeave(CharIDType cid);
	//主动离开副本失败 处理 (目前主要针对竞技场)
	virtual void OnActiveLeaveFaild(CharIDType cid) {};
	//工会解散
	virtual void UnionDismiss();
	//踢出玩家
	virtual void KickPlayer(CharIDType charId);
	//玩家离开副本
	virtual void PlayerLeave(CharIDType cid);
	//通知玩家副本完成
	virtual void OnNotifyFinish(CharIDType charId, DuplicateResult &result);
private:
	//更新分数
	void UpdateScore(CharIDType cid,int32_t monsType, int32_t count,int32_t score);
	//同步增加的分数到中心服 leftTimeScore:剩余时间换算成的积分，主要用在活动结束或者副本完成
	void SyncAddScore(int32_t pass,CharIDType cid,int32_t addScore,int32_t leftTimeScore = 0);
	//删除玩家积分
	void DelCharScore(CharIDType charId);
	int32_t CharKillBossNum(CharIDType charId);
	int32_t CharKillNormalNum(CharIDType charId);
	int32_t CharBossScore(CharIDType charId);
	int32_t CharNormalScroe(CharIDType charId);
	int32_t CharScore(CharIDType charId);
	void CalcLeftSecScore();
private:
	MAP_UINT64_INT32 m_mapCharScore;  //玩家积分
	uint64_t m_totalScore;			 //工会积分
	int32_t m_totalKillBoss;		//工会击杀boss数量
	int32_t m_totalBossScore;		//工会boss积分
	int32_t m_totalKillNormal;		//工会击杀小怪数量
	int32_t m_totalNormalScore;		//工会小怪积分


	MAP_UINT64_INT32 m_mapCharKillBoss;	 //玩家击杀boss数量
	MAP_UINT64_INT32 m_mapCharBossScore; //玩家击杀boss积分
	MAP_UINT64_INT32 m_mapCharKillNormal; //玩家击杀小怪数量
	MAP_UINT64_INT32 m_mapCharNormalScore; //玩家击杀小怪积分
	int32_t m_leftsec;						//剩余时间
	int32_t m_leftsecScore;					//剩余时间积分

	bool m_dismiss;			//是否解散工会了
	bool m_notifyScore;		//是否已经通知中心服积分
};